<?php
class districtdao extends CI_Model{
	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}

	public function getbyid($district_id){
		$this->db->select('*');
		$this->db->from('district');
		$this->db->where('district_id',$district_id);
		$query = $this->db->get();
		$district = $query->row();
		return $district;
	}
	
	public function get_all(){
		$this->db->select('*');
		$this->db->from('district');
		$query = $this->db->get();
		$district = $query->result();
		return $district;
	}
	
	public function insert($district_name,$city_name){
		$data = array(
				'district_name' => $district_name,
				'city_name' => $city_name,
		);
		$str = $this->db->insert_string('district', $data);
		$res = $this->db->query($str);
		return $res;
	}
	
	public function del($district_id) {
		if (intval($district_id) > 0) {
			$this->db->where('district_id', $district_id);
			$this->db->delete('district');
			return ($this->db->affected_rows() == 1) ? TRUE : FALSE;
		}
		return false;
	}
	
	function get_by_city($city_name){
					$this->db->select('district.*');
			$this->db->from('city');
			$this->db->join('district', 'city.city_name
					 = district.city_name');
			$this->db->where('district.city_name',
					$city_name);
			$query = $this->db->get();
			$result = $query->result();
			return $result;
	
	}
}
?>